package com.xbongbong.crm.perform.query.render.insert;

import com.xbongbong.admin.domain.dao.RaidersCorpScoreDao;
import com.xbongbong.crm.abstracts.AbstractCrmNewPageRenderService;
import com.xbongbong.crm.handle.explain.impl.ClueExplainHandleImpl;
import com.xbongbong.crm.help.FineClueHelp;
import com.xbongbong.crm.help.PhoneHelp;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.model.FineClueCompanyModel;
import com.xbongbong.paas.pojo.dto.FormDataAddGetDTO;
import com.xbongbong.paas.pojo.vo.FormDataAddGetVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.FineClueCompanyEntity;
import com.xbongbong.pro.enums.FineClueEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.model.FormTemplateModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 线索 新建 页面渲染
 * @author 吴峰
 * @date 2022/06/21 13:40
 */
@Service("clueNewPageRenderServiceImpl")
public class ClueNewPageRenderServiceImpl extends AbstractCrmNewPageRenderService {

    @Resource
    private ClueExplainHandleImpl clueExplainHandle;
    @Resource
    private FormTemplateModel formTemplateModel;
    @Resource
    private PhoneHelp phoneHelp;
    @Resource
    private FineClueHelp fineClueHelp;

    @Override
    public List<Integer> businessType() {
        return Arrays.asList(XbbRefTypeEnum.CLUE.getCode());
    }

    @Override
    public void businessHandleExplain(FormDataAddGetDTO formDataAddGetDTO, List<FieldAttrEntity> list, PaasFormEntityExt form) throws XbbException {
        FormatExplainDTO formatExplainDTO = new FormatExplainDTO();
        BeanUtil.copyProperties(formDataAddGetDTO, formatExplainDTO);
        formatExplainDTO.setExplainList(list);
        list = clueExplainHandle.newHandleExplain(formatExplainDTO);
        phoneHelp.handlerCustomerRepeat(formDataAddGetDTO.getCorpid(), form.getId(), list, formDataAddGetDTO.getBusinessType());
        // 设置模板字段
        formTemplateModel.setTemplate(formDataAddGetDTO.getCorpid(), form, formDataAddGetDTO.getBusinessType(), formDataAddGetDTO.getLoginUser(), list, 1);
    }

    @Override
    public void formatSaasAttrToReturn(FormDataAddGetDTO formDataAddGetDTO, FormDataAddGetVO formDataAddGetVO, PaasFormEntityExt paasFormEntityExt) throws XbbException {
        // 查看是否能使用精线索的工商查询
        String corpid = formDataAddGetDTO.getCorpid();
        if (fineClueHelp.fineClueUsable(corpid, FineClueEnum.BUSINESS) ) {
            formDataAddGetVO.setIsFineClue(1);
        }
        formDataAddGetVO.setPaasFormEntity(paasFormEntityExt);
    }
}
